< previous page page_132 next page >

Page 132
4. Right-click the ToolBar control and choose Properties. In the toolbar's Property Pages dialog box, set the ImageList property of the toolbar to ImageList1, the name of your image list.
5. On the Buttons tab, click Insert button. The Style property should already be set to the default, 0 tbrNormal. Set the button's Key value to newfile.
6. Set the Image property of the button to the index of the appropriate icon in the ImageList control (which should be 1 if you've followed these steps).
7. Click the Insert button again to add a second button. Set the Style property of this button to 3 - tbrSeparator. This separator button will be seen as blank space between the first and third buttons.
8. Click the Insert button again to add a third button. Set the Style property of this button to 5 - tbrDropdown. Set its Key value to report and its Image property to the index of the other icon from the ImageList control (2). Set its Caption property to REGION.
6. To add items to the button menu for this drop-down button, click the Insert Buttonmenu button. Enter East for the button menu item's Text property.
7. Repeat step 6 for West, South, and Central regions.
8. Click OK to close the Property Pages dialog box. Your drop-down button should now appear on the toolbar.
Enabling the Buttons with Code
You have seen how to set up the toolbar, but until you add code to the toolbar's events, it cannot perform any functions. The buttons of the toolbar do not have events of their own. Instead, you actually write your code for the ButtonClick and ButtonMenuClick events of the toolbar itself. These events pass a Button or ButtonMenu object reference as a parameter to the event procedure. In your code, you use the value of the Button object's Key property to determine which button was actually pressed.
By completing the steps outlined in the preceding sections, you have created a toolbar with buttons that look good and can be clicked, but that don't actually do anything. You need to add code to make them functional. Writing an event procedure for a button on a toolbar is a little different than writing a procedure for a standard command button. Rather than have a separate event procedure for each button and menu, your code must look at object properties to determine which button or button menu item was selected.
Enter the code presented in Listing 6.1 into the form's Code window.
Listing 6.1 TBRDEMO.TXTUsing Code to Activate a Toolbar
Option Explicit
Dim sCurrentRegion As String

Private Sub tbrDemo_ButtonClick(ByVal Button As ComctlLib.Button)
    Select Case UCase(Button.Key)
        Case "NEWFILE"

 
< previous page page_132 next page >